<template>
  <view>
    <van-sticky>
      <van-search
        v-model="title"
        placeholder="请输入搜索关键词"
        input-align="center"
        @input="onSearch"
      />
    </van-sticky>
    <van-tabs v-model="activeName" color="#1989fa" title-active-color="#1989fa"  animated swipeable :ellipsis="false" @click="switchTab">

      <template v-if="this.util.isNotEmpty(activeName)">
        <!-- 文电查询==民航局文电|综合司文电 -->
        <template v-if="activeName == 'mhjwd' || activeName == 'zhswd'">
          <van-tab :title="mhjwdName" name="mhjwd">
            <list2 ref="list2" :newsType="newsType2" :title="searchContent" :finishStatus="finish2" :key='2'></list2>
          </van-tab>
          <van-tab :title="zhswdName" name="zhswd">
            <list3 ref="list3" :newsType="newsType3" :title="searchContent" :finishStatus="finish3" :key='3'></list3>
          </van-tab>
        </template>
        <!-- 局领导重要讲话|局领导活动动态|行业动态|互联网摘要 -->
        <template v-else>
          <van-tab :title="zywjName" name="zywj">
            <list1 ref="list1" :newsType="newsType1" :title="searchContent" :finishStatus="finish1" :key='1'></list1>
          </van-tab>
          <van-tab :title="mhywName" name="mhyw">
            <list4 ref="list4" :newsType="newsType4" :title="searchContent" :finishStatus="finish4" :key='4'></list4>
          </van-tab>
          <van-tab :title="mhxwName" name="mhxw">
            <list5 ref="list5" :newsType="newsType5" :title="searchContent" :finishStatus="finish5" :key='5'></list5>
          </van-tab>
          <van-tab :title="hlwzyName" name="hlwzy">
            <list6 ref="list6" :newsType="newsType6" :title="searchContent" :finishStatus="finish6" :key='6'></list6>
          </van-tab>
        </template>
      </template>
    </van-tabs>
    <van-divider/>
  </view>
</template>

<script>
import list1 from 'pages/caac/components/newsList/compo-list.vue';
import list2 from 'pages/caac/components/newsList/compo-list.vue';
import list3 from 'pages/caac/components/newsList/compo-list.vue';
import list4 from 'pages/caac/components/newsList/compo-list.vue';
import list5 from 'pages/caac/components/newsList/compo-list.vue';
import list6 from 'pages/caac/components/newsList/compo-list.vue';
import list7 from 'pages/caac/components/newsList/compo-list.vue';

export default {
  components: {
    list1,
    list2,
    list3,
    list4,
    list5,
    list6,
    list7,
  },
  props: {
    tabName: {
      type: String,
      default: 'a'
    }
  },

  onLoad: function (option) {
    if(this.util.isNotEmpty(option)){
      this.activeName = option.activeName
      if(this.activeName.indexOf('wd') != -1){
        uni.setNavigationBarTitle({
          title:'文电'
        })
      }else if(this.activeName=='tzgg'){
        uni.setNavigationBarTitle({
          title:'通知公告'
        })
      }
    }
    this.switchTab(this.activeName)
  },

  data() {
    return {
      activeName: 'zywj',
      zywjName: '局领导重要讲话',
      mhjwdName: '民航局文电',
      zhswdName: '综合司文电',
      mhywName: '局领导活动动态',
      mhxwName: '行业动态',
      hlwzyName: '互联网摘要',
      tzggName: '通知公告',
      newsType1: 'zywj',
      newsType2: 'mhjwd',
      newsType3: 'zhswd',
      newsType4: 'mhyw',
      newsType5: 'mhxw',
      newsType6: 'hlwzy',
      newsType7: 'tzgg',
      finish1: true,
      finish2: true,
      finish3: true,
      finish4: true,
      finish5: true,
      finish6: true,
      finish7: true,
      title:'',//搜索关键字
      searchContent:''
    }
  },
  methods: {
    onSearch(){
      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        this.searchContent= this.title
      },300)

    },
    switchTab(name) {
      this.title = '' //tab 切换的时候清空搜索关键字
      this.searchContent = ''
      this.finish1 = true
      this.finish2 = true
      this.finish3 = true
      this.finish4 = true
      this.finish5 = true
      this.finish6 = true
      this.finish7 = true

      if (name == 'zywj') {
        this.finish1 = false
      }
      if (name == 'mhjwd') {
        this.finish2 = false
      }
      if (name == 'zhswd') {
        this.finish3 = false
      }
      if (name == 'mhyw') {
        this.finish4 = false
      }
      if (name == 'mhxw') {
        this.finish5 = false
      }
      if (name == 'hlwzy') {
        this.finish6 = false
      }
      if (name == 'tzgg') {
        this.finish7 = false
      }

    },

  },
}
</script>

<style scoped>
.van-cell__title {
    min-width: 70%;
    span {
        display: inline-block;
        text-align: left;
        word-break: break-all;
    }
}
</style>
